<?php
namespace ProjetA\GroupeBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use ProjetA\GroupeBundle\Form\TextType;
use ProjetA\GroupeBundle\Entity\Groupe as Groupe;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of PageGroupeType
 *
 * @author Gael
 */
class PageGroupeType extends AbstractType {
    //put your code here
    protected $page;
    protected $groupe;
    function __construct($page,Groupe $groupe = null) {
        $this->page = $page;
        $this->groupe=$groupe;
        
    }
    
    public function buildForm(FormBuilder $builder, array $options)
    {
        if($this->edit()){
            foreach ($this->page->getAttributs() as $value) {
                switch($value->getType()){
                    case'text':
                        $builder->add($value->getLibelle(),new TextType($value->getLibelle()));
                        //$builder->add("hehehe",new TextType($value->getLibelle()));
                    break;
                    case'date':
                        $builder->add($value->getLibelle(),new DateType($value->getLibelle()));
                        //$builder->add("hehehe",new TextType($value->getLibelle()));
                    break;
                    case'email':
                        $builder->add($value->getLibelle(),new TextType($value->getLibelle()));
                    break;
                }

            }  
        }else{
            foreach ($this->page->getAttributs() as $value) {
                switch($value->getType()){
                    case'text':
                        $builder->add($value->getLibelle(),new TextType($value->getLibelle(),$this->groupe->getTextByName($value->getLibelle())));
                    break;
                    case'date':
                        $builder->add($value->getLibelle(),new DateType($value->getLibelle(),$this->groupe->getDateByName($value->getLibelle())));
                        
                    break;
                    case'email':
                        $builder->add($value->getLibelle(),new TextType($value->getLibelle(),$this->groupe->getTextByName($value->getLibelle())));
                    break;
                }

            }
            
        }
        
       
    }
    public function getName() {
        return 'projeta_groupebundle_pagegroupetype';
    }
    Public function edit(){
        if($this->groupe == null){
            return true;
        }else{
            return false;
        }
    }
}

?>
